Initial value problem $x(0) = X_0$ (inital conditions). Solution is given by
$$x(t)=X_0\exp\left(r\cdot t\right)$$import numpy as np
import pandas as pd
from functools import partial
from scipy.integrate import odeint
def exponential_growth(x, t, r):
"""
Exponential Growth model.
"""
dxdt = r*x
return dxdt
initial_conditions = [10, 100, 300, 500]
import matplotlib.pyplot as plt
t_span = np.linspace(0, 5, num=100)
r_values =[ -2, 0, 2]
fig, ax = plt.subplots(1,1, figsize=(15.5, 7))
for ic in initial_conditions:
y = odeint(exponential_growth, y0=ic, t=t_span, args=(r_values[0],) )
ax.plot(t_span, y, label='x(0)={}'.format(ic))
ax.set_xlabel('Time')
ax.set_ylabel('x(t)')
ax.set_title('r={}'.format(r_values[0]))
ax.legend()
##############################################
fig, ax = plt.subplots(1,2, figsize=(15.5, 7))
for ic in initial_conditions:
y = odeint(exponential_growth, y0=ic, t=t_span, args=(r_values[0],) )
ax[0].plot(t_span, y, label='x(0)={}'.format(ic))
ax[0].set_xlabel('Time')
ax[0].set_ylabel('x(t)')
ax[0].set_title('r={}'.format(r_values[0]))
y = odeint(exponential_growth, y0=ic, t=t_span, args=(r_values[-1],) )
ax[1].plot(t_span, y, label='x(0)={}'.format(ic))
ax[1].set_xlabel('Time')
ax[1].set_ylabel('x(t)')
ax[1].set_title('r={}'.format(r_values[-1]))
ax[1].set_ylim([0, 1000])
xlimit = (-1.3, 1.3)
ylimit = (-0.5, 0.5)
def logistic_growth(x, t, r, K):
"""
Logistic Growth model.
"""
dxdt = r*x*(1-x/K)
return dxdt
initial_conditions = [10, 100, 300, 400]
import matplotlib.pyplot as plt
t_span = np.linspace(0, 5, num=100)
r_values =[ -2, 0, 2]
K = 500
fig, ax = plt.subplots(1,1, figsize=(15.5, 7))
for ic in initial_conditions:
y = odeint(logistic_growth, y0=ic, t=t_span, args=(r_values[0],500) )
ax.plot(t_span, y, label='x(0)={}'.format(ic))
ax.set_xlabel('Time')
ax.set_ylabel('x(t)')
ax.set_title('r={}'.format(r_values[0]))
ax.legend()
##############################################
fig, ax = plt.subplots(1,1, figsize=(15.5, 7))
for ic in initial_conditions:
y = odeint(logistic_growth, y0=ic, t=t_span, args=(r_values[0],500) )
ax.plot(t_span, y, label='x(0)={}'.format(ic))
ax.set_xlabel('Time')
ax.set_ylabel('x(t)')
ax.set_title('r={}'.format(r_values[0]))
y = odeint(logistic_growth, y0=ic, t=t_span, args=(r_values[-1],500) )
ax.plot(t_span, y, label='x(0)={}'.format(ic), linestyle='--')
ax.set_xlabel('Time')
ax.set_ylabel('x(t)')
ax.set_title('continious line (-) r=-2 | non-continuos line (--): r=2')
Text(0.5, 1.0, 'continious line (-) r=-2 | non-continuos line (--): r=2')